package com.framework.modules.base.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.framework.common.config.SystemConfigName;
import com.framework.common.model.config.ConfigPaymentRateMoney2Coin;
import com.framework.common.model.config.ConfigServers;
import com.framework.common.model.config.ConfigUserTags;
import com.framework.common.utils.QuickHelper;
import com.framework.common.utils.R;
import com.framework.modules.base.entity.GiftEntity;
import com.framework.modules.base.service.GiftService;
import com.framework.modules.sys.service.SysConfigService;
import com.framework.modules.base.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import java.util.*;


/**
 * 用户
 *
 * @author MIT
 * @email litmiss@gmail.com
 * @date 2020-10-20 18:11:40
 */
@Service
@RestController
@RequestMapping("/config")
@Api(tags = "系统配置信息")
public class ConfigController {

    @Autowired
    private GiftService giftService;



    /**
     * @return
     * 默认头像地址 assets.user.defaultAvatar =
     * 特权配置 assets.matching.daily.limit，兴趣匹配=interset,形象匹配=sence,语音匹配=voice,定位匹配=location
     * assets.matching.daily.limit={
     * 	"interest": 30,
     * 	"sence": 30,
     * 	"voice": 30,
     * 	"location":30
     * }
     * 用户常用标签 assets.user.defaultTags
     *  单身,娱乐,交友,结婚,户外,电竞,电影,音乐,宠物,学习,旅游,极限运动
     * 用户发布动态限制 assets.user.newpost.limit = {
     * 	"max_images_count": 一次最多上传的视频数
     * 	"max_video_count": 一次最多上传的照片数量
     * 	"max_voice_seconds": 一次最多上传的声音秒数
     * }
     * assets.payment.defaultMoneyList  [10,50,100,200,500,1000] 充值金额列表
     * //充值金额比例
     * pay.rate.money2coin {
     * 	"android": 10,
     * 	"ios": 7
     * }
     *
     * assets.data.gifts 礼物列表
     *
     * assets.payment.typeDefined 账单类型
     *
     * assets.income.typeDefined 收益类型
     *
     * assets.live.announcement直播提示警告语
     *
     * assets.user.report.category 举报类目
     *
     *
     */
    @CrossOrigin
    @GetMapping("/assets")
    @ApiOperation("获取配置信息")
    public R assets() {
        Map<String, Object> map = new HashMap<>();
        map.put("debug", QuickHelper.getConfigValue(SystemConfigName.DEBUG,Boolean.class));
        map.put("assets.user.defaultAvatar", QuickHelper.getConfigJSONObject(SystemConfigName.ASSETS_USER_DEFAULTAVATAR));
        map.put("assets.matching.daily.limit", QuickHelper.getConfigJSONObject(SystemConfigName.ASSETS_MATCHING_DAILY_LIMIT));
        map.put("assets.user.newpost.limit", QuickHelper.getConfigJSONObject(SystemConfigName.ASSETS_USER_NEWPOST_LIMIT));
        map.put("assets.payment.defaultMoneyList", QuickHelper.getConfigJSONArray(SystemConfigName.ASSETS_PAYMENT_DEFAULTMONEYLIST));
        map.put("pay.rate.money2coin",QuickHelper.getConfigValue(SystemConfigName.PAY_RATE_MONEY2COIN, ConfigPaymentRateMoney2Coin.class));
        map.put("assets.data.gifts", giftService.selectList(new EntityWrapper<GiftEntity>()));
        map.put("assets.payment.typeDefined", QuickHelper.getConfigJSONObject(SystemConfigName.ASSETS_PAYMENT_TYPEDEFINED));
        map.put("assets.income.typeDefined", QuickHelper.getConfigJSONObject(SystemConfigName.ASSETS_INCOME_TYPEDEFINED));
        map.put("assets.user.tags", QuickHelper.getConfigValue(SystemConfigName.ASSETS_USER_TAGS, ConfigUserTags.class));
        map.put("assets.device.upload.interval", QuickHelper.getConfigIntegerValue(SystemConfigName.DEVICE_UPLOAD_INTERVAL));
        map.put("assets.live.announcement", QuickHelper.getConfigString(SystemConfigName.ASSETS_LIVE_ANNOUNCEMENT));
        map.put("assets.user.report.category", QuickHelper.getConfigValue(SystemConfigName.ASSETS_USER_REPORT_CATEGORY,JSONArray.class));
        map.put("assets.servers", QuickHelper.getConfigValue(SystemConfigName.SERVERS, ConfigServers.class));

        return R.ok("获取成功").put("data", map);
    }
}
